import bianliang from "./bianliang.js";

class Tool {
	constructor() {
		var temp = parseInt(Math.random() * 2);
		if (temp == 0) {
			this.type = 0;
			this.img = bianliang.resObj[6];
		} else if (temp == 1) {
			this.type = 1;
			this.img = bianliang.resObj[7];
		}
		this.width = this.img.width;
		this.height = this.img.height;
		this.x = parseInt(Math.random() * 480);
		if (this.x > 480 - this.width) {
			this.x = 480 - this.width;
		}
		this.y = this.height * (-1);
	}
	move() {
		this.y += 2;
		if (this.y > 850) {
			var index = bianliang.toolList.indexOf(this);
			bianliang.toolList.splice(index, 1);
		}
	}
	draw(ctx) {
		this.move();
		ctx.drawImage(this.img, this.x, this.y, this.width, this.height);
	}
}
export default Tool;
